import time
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tqdm import tqdm


class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.master = master
        self.grid(row=1, column=1)

        self.createWidget()

    def createWidget(self):
        '''创建登录界面的组件'''
        # 创建登录框
        self.label01 = Label(self, text='欢迎使用此工具')
        self.label01.grid(row=0, column=0, columnspan=2, rowspan=2)
        # StringVar变量绑定到指定的组件
        # StringVar变量的值发生改变，组件内容也变化
        # 组件内容发生变化，StringVar变量的值也发生变化

        # 创建导出网址名框
        self.label02 = Label(self, text='导出网址')
        self.label02.grid(row=2, column=0)
        v1 = StringVar(value='http://www.autohome.com/')
        # v1 = StringVar()
        self.entry01 = Entry(self, textvariable=v1)
        self.entry01.grid(row=2, column=1)

        but1 = Button(self, text='确定', command=self.login).grid(row=2, column=2)


    def login(self):
        Label(self,text='开始解析网页数据').grid(row=3, column=0)
        username = self.entry01.get()
        # print("------")
        self.file1(username)
        # if username == 'QinAfeng' and pwd == '123456':
        #     messagebox.showinfo('TK世界', '恭喜你登录成功')
        # else:
        #     messagebox.showinfo('TK世界', '登录失败！用户名或密码错误！')
        # return username
        # print("un:",username)
        # return username
    def file1(self,username):
        print("un2:",username)
        # time.sleep(10)
        v2 = StringVar(value='oither')
        self.entry02 = Entry(self,textvariable=v2).grid(row=4, column=1)
        print("完成了")
        tqdm(100)

    def tqdm1(self,number):
        with tqdm(iterable=range(number), desc='获取进度', unit='个', total=number) as pgbr:
            for _td in range(number):
                pgbr.update(1)


if __name__ == '__main__':
    root = Tk()
    # root.geometry('200x200+200+300')
    # 设置窗口大小
    width = 500
    height = 300
    # 获取屏幕尺寸以计算布局参数，使窗口居屏幕中央
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 3)
    root.geometry(alignstr)
    root.title('Entry实现登录')
    app = Application(root)
    root.mainloop()